package com.gupao.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.gupao.entity.User;
import com.gupao.service.UserService;

@Component
public class OpenapiUserDetailsService implements UserDetailsService {

	@Autowired
	UserService userService;

	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = userService.selectByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException("用户不存在");
		}
		return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), !user.isLocked(),
				true, true, true, AuthorityUtils.commaSeparatedStringToAuthorityList("openapi"));
	}

}
